#include "display_menue.h"


void     apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination);
uint8_t  display_button_pressed(uint16_t x, uint16_t y, uint8_t button_tmp);
uint32_t display_set_sdl_userevent(uint32_t intervall, void *parameter);

void display_reflash_main(display_menue *display_tmp, uint8_t *state);
void display_reflash_show(display_menue *display_tmp, uint8_t *state);
void display_reflash_main_work(display_menue *display_tmp, uint8_t *state);
void display_reflash_roomlist(display_menue *display_tmp, uint8_t *state);
void display_reflash_seminarroom(display_menue *display_tmp, uint8_t *state);

void display_reflash_main(display_menue *display_tmp, uint8_t *state){

   struct tm *newtime;
   time_t long_time;
   char buffer[80];
   time( &long_time ); 
   newtime = localtime( &long_time ); 
   sprintf(buffer,"%02d:%02d",newtime->tm_hour, newtime->tm_min);
   display_tmp->watch_text = TTF_RenderText_Solid(display_tmp->font_liberation_big,
                              buffer   , 
                              display_tmp->white);

   sprintf(buffer,"%d ""\xB0""C",rand() % 25);
   display_tmp->roomtempr_text = TTF_RenderText_Solid(display_tmp->font_liberation_normal,
                              buffer   , 
                              display_tmp->black);

   apply_surface(  0,   0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(295, 310,display_tmp->thermometer_pic,display_tmp->screen);
   apply_surface(680, 365,display_tmp->next_button,display_tmp->screen);
   apply_surface(200,  95,display_tmp->time_frame,display_tmp->screen);
   apply_surface(245, 120,display_tmp->watch_text,display_tmp->screen);
   apply_surface(380, 330,display_tmp->roomtempr_text,display_tmp->screen);  
   
   SDL_Flip(display_tmp->screen); 
   SDL_FreeSurface(display_tmp->roomtempr_text); 

}

void display_reflash_main_work(display_menue *display_tmp, uint8_t *state){

   struct tm *newtime;
   time_t long_time;
   char buffer[80];
   time( &long_time ); 
   newtime = localtime( &long_time ); 
   sprintf(buffer,"%02d:%02d",newtime->tm_hour, newtime->tm_min);
   display_tmp->watch_text = TTF_RenderText_Solid(display_tmp->font_liberation_tall,
                              buffer   , 
                              display_tmp->white);
   int i = rand() % 2;

   apply_surface(  0,  0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(680,365,display_tmp->next_button,display_tmp->screen);
   apply_surface(300,300,display_tmp->little_watch_frame,display_tmp->screen);
   apply_surface(310,315,display_tmp->watch_text,display_tmp->screen);
 
   if(i){
      apply_surface(150, 50,display_tmp->red_frame,display_tmp->screen);
      apply_surface(250,130,display_tmp->red_text,display_tmp->screen);
   }
   else{
      apply_surface(150, 50,display_tmp->green_frame,display_tmp->screen);
      apply_surface(280,130,display_tmp->green_text,display_tmp->screen);
   }
   SDL_Flip(display_tmp->screen); 

}

void display_reflash_show(display_menue *display_tmp, uint8_t *state){

     char buffer_tmp[80];
     int i = rand() % 2;
     

     GetTempSensorValue("wohnzimmer:temperatur_aussen", 0, &display_tmp->tempr_tmp);
     sprintf(buffer_tmp,"Innen     %.1f ""\xB0""C",display_tmp->tempr_tmp);


     
     display_tmp->temprin_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    buffer_tmp, 
                                                    display_tmp->white);

     
     sprintf(buffer_tmp,"Au""\xDF""en      %.1d ""\xB0""C",rand() % 30);
     display_tmp->temprout_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                      buffer_tmp, 
                                                    display_tmp->white);

     if(i)
        display_tmp->windowone_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Fenster1     offen", 
                                                    display_tmp->red);
     else
        display_tmp->windowone_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Fenster1       zu", 
                                                    display_tmp->green);

     i = rand() % 2;
     if(i)
        display_tmp->windowtwo_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Fenster2     offen ", 
                                                    display_tmp->red);
     else
        display_tmp->windowtwo_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Fenster2       zu ", 
                                                    display_tmp->green);
     
     apply_surface(120,120,display_tmp->roomtempr_frame,display_tmp->screen);
     apply_surface(435,120,display_tmp->roomwindow_frame,display_tmp->screen);   
     apply_surface(160,180,display_tmp->temprin_text,display_tmp->screen);
     apply_surface(160,260,display_tmp->temprout_text,display_tmp->screen); 
     apply_surface(470,180,display_tmp->windowone_text,display_tmp->screen);
     apply_surface(470,260,display_tmp->windowtwo_text,display_tmp->screen);

     SDL_Flip(display_tmp->screen);
     SDL_FreeSurface(display_tmp->temprin_text);
     SDL_FreeSurface(display_tmp->temprout_text);
     SDL_FreeSurface(display_tmp->windowone_text);
     SDL_FreeSurface(display_tmp->windowtwo_text); 

}

void display_reflash_roomlist(display_menue *display_tmp, uint8_t *state){

     int i = rand() % 2;

     if(i)
        apply_surface(300,130,display_tmp->red_pic,display_tmp->screen);
     else
        apply_surface(300,130,display_tmp->green_pic,display_tmp->screen);

     i = rand() % 2;

     if(i)
        apply_surface(300,190,display_tmp->red1_pic,display_tmp->screen);
     else
        apply_surface(300,190,display_tmp->green1_pic,display_tmp->screen);

     i = rand() % 2;

     if(i)
        apply_surface(300,250,display_tmp->red2_pic,display_tmp->screen);
     else
        apply_surface(300,250,display_tmp->green2_pic,display_tmp->screen);

     i = rand() % 2;

     if(i)
        apply_surface(300,310,display_tmp->red3_pic,display_tmp->screen);
     else
        apply_surface(300,310,display_tmp->green3_pic,display_tmp->screen);

     SDL_Flip(display_tmp->screen);
}

void display_reflash_seminarroom(display_menue *display_tmp, uint8_t *state){

     int i = rand() % 2;
     troomname* rn1;

     char buffer_tmp[80];
     

     GetAlternativeRooms("G.216", 5, &rn1);
     sprintf(buffer_tmp,"%s       %s",rn1[0],rn1[1]);

 
     
     display_tmp->roomstat_text = TTF_RenderText_Solid(display_tmp->font_liberation_normal,
                                                    buffer_tmp, 
                                                    display_tmp->black);



     if(i){
        apply_surface(600, 43,display_tmp->semi_allocation1_frame,display_tmp->screen); 
        apply_surface(620,57,display_tmp->semi_full_text,display_tmp->screen);
     }else{
        apply_surface(600, 43,display_tmp->semi_allocation2_frame,display_tmp->screen); 
        apply_surface(630,57,display_tmp->semi_free_text,display_tmp->screen);
     }

     apply_surface(230,270,display_tmp->roomstat_text,display_tmp->screen); 

     SDL_Flip(display_tmp->screen);    
     free(rn1);
}

//Selfmade event for timers
Uint32 display_set_sdl_userevent(uint32_t intervall, void *parameter){

  SDL_Event     event;
  SDL_UserEvent userevent;

  userevent.type  = SDL_USEREVENT;
  userevent.code  = 0; 
  userevent.data1 = NULL;
  userevent.data2 = NULL;

  event.type      = SDL_USEREVENT;
  event.user      = userevent;

  SDL_PushEvent(&event);
  return intervall;

}
                                             
//Loading pictures and fonts
int  display_init(display_menue *display_tmp ,uint8_t *state){
   
   //Loading of the home pictures
   if ((display_tmp->main_frame = IMG_Load("pics/main.png")) == NULL )
      return -1;  
   if ((display_tmp->time_frame = IMG_Load("pics/watch.png")) == NULL )
      return -1;
   if ((display_tmp->thermometer_pic = IMG_Load("pics/thermometer.png")) == NULL )
      return -1;
   if ((display_tmp->small_thermometer_pic = IMG_Load("pics/thermometer_show.png")) == NULL )
      return -1;
   if ((display_tmp->window_pic = IMG_Load("pics/window.png")) == NULL )
      return -1;
   if ((display_tmp->roomtitle_frame = IMG_Load("pics/blue_bar.png")) == NULL )
      return -1;
   if ((display_tmp->roomwindow_frame = IMG_Load("pics/blacky.png")) == NULL )
      return -1;
   if ((display_tmp->roomtempr_frame = IMG_Load("pics/blacky.png")) == NULL )
      return -1;
   if ((display_tmp->next_button = IMG_Load("pics/pfeil_rechts.png")) == NULL )
      return -1;
   if ((display_tmp->back_button = IMG_Load("pics/back.png")) == NULL )
      return -1;
   if ((display_tmp->home_button = IMG_Load("pics/home.png")) == NULL )
      return -1;
   if ((display_tmp->work_frame = IMG_Load("pics/grey_box.png")) == NULL )
      return -1;
   if ((display_tmp->living_frame = IMG_Load("pics/grey_box.png")) == NULL )
      return -1;
   if ((display_tmp->bath_frame = IMG_Load("pics/grey_box.png")) == NULL )
      return -1;
   if ((display_tmp->kitchen_frame = IMG_Load("pics/grey_box.png")) == NULL )
      return -1;
   if ((display_tmp->sleep_frame = IMG_Load("pics/grey_box.png")) == NULL )
      return -1;

   //Loading of the work pictures
   if ((display_tmp->little_watch_frame = IMG_Load("pics/little_watch.png")) == NULL )
      return -1;
   if ((display_tmp->semi_room_frame = IMG_Load("pics/grey_work.png")) == NULL )
      return -1;
   if ((display_tmp->bureau_frame = IMG_Load("pics/grey_work.png")) == NULL )
      return -1;
   if ((display_tmp->list_title_frame = IMG_Load("pics/black1_bar.png")) == NULL )
      return -1;     
   if ((display_tmp->info_semi1_button = IMG_Load("pics/info.png")) == NULL )
      return -1;     
   if ((display_tmp->info_semi2_button = IMG_Load("pics/info.png")) == NULL )
      return -1;     
   if ((display_tmp->info_semi3_button = IMG_Load("pics/info.png")) == NULL )
      return -1;     
   if ((display_tmp->info_semi4_button = IMG_Load("pics/info.png")) == NULL )
      return -1;     
   if ((display_tmp->info_bureau1_button = IMG_Load("pics/info.png")) == NULL )
      return -1;    
   if ((display_tmp->info_bureau2_button = IMG_Load("pics/info.png")) == NULL )
      return -1;    
   if ((display_tmp->timetable_frame = IMG_Load("pics/black_timetable.png")) == NULL )
      return -1;    
   if ((display_tmp->timetable_info_frame = IMG_Load("pics/timetable_info.png")) == NULL )
      return -1;    
   if ((display_tmp->semi_room_free_frame = IMG_Load("pics/black2_bar.png")) == NULL )
      return -1;    
   if ((display_tmp->semi_info_frame = IMG_Load("pics/semi_info.png")) == NULL )
      return -1;    
   if ((display_tmp->next_room_info_frame = IMG_Load("pics/black3_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->semi_allocation1_frame = IMG_Load("pics/little_red.png")) == NULL )
      return -1; 
   if ((display_tmp->semi_allocation2_frame = IMG_Load("pics/little_green.png")) == NULL )
      return -1; 
   if ((display_tmp->red_pic = IMG_Load("pics/red_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->green_pic = IMG_Load("pics/green_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->red1_pic = IMG_Load("pics/red_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->green1_pic = IMG_Load("pics/green_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->red2_pic = IMG_Load("pics/red_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->green2_pic = IMG_Load("pics/green_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->red3_pic = IMG_Load("pics/red_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->green3_pic = IMG_Load("pics/green_bar.png")) == NULL )
      return -1; 
   if ((display_tmp->red_frame = IMG_Load("pics/big_red.png")) == NULL )
      return -1; 
   if ((display_tmp->green_frame = IMG_Load("pics/big_green.png")) == NULL )
      return -1; 

   //Initialisation of the fontcolours
   display_tmp->black.r =0;   // redpart   of the colour
   display_tmp->black.g =0;   // greenpart of the colour
   display_tmp->black.b =0;   // bluepart  of the colour

   display_tmp->green.r =0;
   display_tmp->green.g =255;
   display_tmp->green.b =0;

   display_tmp->red.r =255;
   display_tmp->red.g =0;
   display_tmp->red.b =0;

   display_tmp->white.r = 255;
   display_tmp->white.g = 255;
   display_tmp->white.b = 255;
   
   //Initialisation of SDL Truetypefonts functions
   TTF_Init();

   //Loading the fonts
   if ((display_tmp->font_liberation_minimal = TTF_OpenFont("LiberationSans-Regular.ttf", 10)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_mini = TTF_OpenFont("LiberationSans-Regular.ttf", 16)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_small = TTF_OpenFont("LiberationSans-Regular.ttf", 20)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_middle = TTF_OpenFont("LiberationSans-Regular.ttf", 28)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_normal = TTF_OpenFont("LiberationSans-Regular.ttf", 40)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_tall = TTF_OpenFont("LiberationSans-Regular.ttf", 60)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_taller = TTF_OpenFont("LiberationSans-Regular.ttf",80)) == NULL )
      return -1;
   if ((display_tmp->font_liberation_big = TTF_OpenFont("LiberationSans-Regular.ttf", 120)) == NULL )
      return -1;

   //Make the fonts fat
   TTF_SetFontStyle(display_tmp->font_liberation_middle, TTF_STYLE_BOLD);
   TTF_SetFontStyle(display_tmp->font_liberation_small, TTF_STYLE_BOLD);
   TTF_SetFontStyle(display_tmp->font_liberation_normal, TTF_STYLE_BOLD);
   TTF_SetFontStyle(display_tmp->font_liberation_tall, TTF_STYLE_BOLD);

   //Fill text in the home textvariables
   display_tmp->work_text = TTF_RenderText_Solid( display_tmp->font_liberation_small,
                                                    "Arbeit", 
                                                    display_tmp->black);
   display_tmp->living_text = TTF_RenderText_Solid( display_tmp->font_liberation_small,
                                                    "Wohnen", 
                                                    display_tmp->black);
   display_tmp->bath_text = TTF_RenderText_Solid( display_tmp->font_liberation_small,
                                                    "Bad", 
                                                    display_tmp->black);
   display_tmp->sleep_text = TTF_RenderText_Solid( display_tmp->font_liberation_small,
                                                    "Schlafen", 
                                                    display_tmp->black);
   display_tmp->kitchen_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "K""\xFC""che", 
                                                    display_tmp->black);
   display_tmp->showwork_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "Arbeitszimmer", 
                                                    display_tmp->white);
   display_tmp->showliving_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "Wohnzimmer", 
                                                    display_tmp->white);
   display_tmp->showbath_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "Badezimmer", 
                                                    display_tmp->white);
   display_tmp->showsleep_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "Schlafzimmer", 
                                                    display_tmp->white);
   display_tmp->showkitchen_text = TTF_RenderText_Solid(display_tmp->font_liberation_middle,
                                                    "K""\xFC""che", 
                                                    display_tmp->white);

   //Fill text in the work textvariables
   display_tmp->title_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "         Seminarr""\xE4""ume            "
                                                    "            B""\xFC""ros", 
                                                    display_tmp->white);

   display_tmp->semi1_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "S 100", 
                                                    display_tmp->black);
   display_tmp->semi2_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "S 101", 
                                                    display_tmp->black);
   display_tmp->semi3_text = TTF_RenderText_Solid(display_tmp->font_liberation_middle,
                                                    "S 102", 
                                                    display_tmp->black);
   display_tmp->semi4_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "S 103", 
                                                    display_tmp->black);
   display_tmp->bureau1_text = TTF_RenderText_Solid( display_tmp->font_liberation_middle,
                                                    "B 010", 
                                                    display_tmp->black);
   display_tmp->bureau2_text = TTF_RenderText_Solid(display_tmp->font_liberation_middle,
                                                    "B 011", 
                                                    display_tmp->black);
   display_tmp->green_text = TTF_RenderText_Solid( display_tmp->font_liberation_taller,
                                                    " FREI", 
                                                    display_tmp->white);
   display_tmp->red_text = TTF_RenderText_Solid(display_tmp->font_liberation_taller,
                                                    "BELEGT", 
                                                    display_tmp->white);
   display_tmp->semi_full_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "belegt ", 
                                                    display_tmp->white);
   display_tmp->semi_free_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "frei ", 
                                                    display_tmp->white);
   display_tmp->roomname_semi1_text = TTF_RenderText_Solid( display_tmp->font_liberation_minimal,
                                                    "Allzweckseminarraum", 
                                                    display_tmp->black);
   display_tmp->roomname_semi2_text = TTF_RenderText_Solid(display_tmp->font_liberation_minimal,
                                                    "Allzweckseminarraum", 
                                                    display_tmp->black);
   display_tmp->roomname_semi3_text = TTF_RenderText_Solid( display_tmp->font_liberation_minimal,
                                                    "Computerseminarraum", 
                                                    display_tmp->black);
   display_tmp->roomname_semi4_text = TTF_RenderText_Solid(display_tmp->font_liberation_minimal,
                                                    "Allzweckseminarraum", 
                                                    display_tmp->black);
   display_tmp->roomname_bureau1_text = TTF_RenderText_Solid(display_tmp->font_liberation_minimal,
                                                    "Verwaltungsb""\xFC""ro", 
                                                    display_tmp->black);
   display_tmp->roomname_bureau2_text = TTF_RenderText_Solid(display_tmp->font_liberation_minimal,
                                                    "Prof. Sowieso", 
                                                    display_tmp->black);
/*---------------------------------------BUREAU TEXTS------------------------------------------------*/
   display_tmp->bureau1_time_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "     \xD6""ffnungszeiten:",  
                                                    display_tmp->white);  
   display_tmp->bureau1_time1_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Montag       09:00 - 12:00   14:00 - 17:30  ",  
                                                    display_tmp->white);
   display_tmp->bureau1_time2_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Dienstag                09:00 - 12:00",  
                                                    display_tmp->white);
   display_tmp->bureau1_time3_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Mittwoch                09:00 - 12:00",  
                                                    display_tmp->white);
   display_tmp->bureau1_time4_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Donnerstag                   FREI",  
                                                    display_tmp->white);
   display_tmp->bureau1_time5_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Freitag                  09:00 - 12:00",  
                                                    display_tmp->white);
   display_tmp->bureau1_info1_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Verwaltungsb""\xFC""ro B 010",  
                                                    display_tmp->black);
   display_tmp->bureau1_info2_text = TTF_RenderText_Solid(display_tmp->font_liberation_mini,
                                                    "(An Sonn- und Feiertagen geschlossen)",  
                                                    display_tmp->black);
   display_tmp->bureau2_time_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "     Sprechstunden:",  
                                                    display_tmp->white);  
   display_tmp->bureau2_time1_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Montag                             FREI",  
                                                    display_tmp->white);
   display_tmp->bureau2_time2_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Dienstag                           FREI",  
                                                    display_tmp->white);
   display_tmp->bureau2_time3_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Mittwoch                     13:00 - 15:30",  
                                                    display_tmp->white);
   display_tmp->bureau2_time4_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Donnerstag                        FREI",  
                                                    display_tmp->white);
   display_tmp->bureau2_time5_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "      Freitag                              FREI",  
                                                    display_tmp->white);
   display_tmp->bureau2_info1_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "B""\xFC""ro von Professor Sowieso B 011",  
                                                    display_tmp->black);
   display_tmp->bureau2_info2_text = TTF_RenderText_Solid(display_tmp->font_liberation_mini,
                                                    "(Ausserhalb der Srechstunden bitte einen Termin vereinbaren)",  
                                                    display_tmp->black);
/*---------------------------------------SEMINARROOM TEXTS------------------------------------------*/
   display_tmp->semi_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Zur Verf""\xFC""gung stehende R""\xE4""ume:",  
                                                    display_tmp->white);
   display_tmp->semi1_title_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Seminarraum S 100",  
                                                    display_tmp->white);
   display_tmp->semi1_info_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Allzweckseminarraum, geeignet f""\xFC""r diverse Seminare",  
                                                    display_tmp->black);
   display_tmp->semi2_title_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Seminarraum S 101",  
                                                    display_tmp->white);
   display_tmp->semi2_info_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Allzweckseminarraum, geeignet f""\xFC""r diverse Seminare",  
                                                    display_tmp->black);
   display_tmp->semi3_title_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Seminarraum S 102",  
                                                    display_tmp->white);
   display_tmp->semi3_info_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Computerseminarraum, geeignet f""\xFC""r EDV Seminare",  
                                                    display_tmp->black);
   display_tmp->semi4_title_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Seminarraum S 103",  
                                                    display_tmp->white);
   display_tmp->semi4_info_text = TTF_RenderText_Solid(display_tmp->font_liberation_small,
                                                    "Allzweckseminarraum, geeignet f""\xFC""r diverse Seminare",  
                                                    display_tmp->black);


/*-------------------------------------------------------------------------------------------------*/
   //Initialise the SDL library funktions
   SDL_Init( SDL_INIT_EVERYTHING );
   //Setup of the screen
   display_tmp->screen = SDL_SetVideoMode( 800, 480, 32, SDL_SWSURFACE /*| SDL_FULLSCREEN*/ );
   //Hide the mousecursor
   //SDL_ShowCursor(0);

   return 0;
}

/*----------------------------------HOME--------------------------------------*/

//Mainscreen of the homeapplication
void display_main_window(display_menue *display_tmp ,uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0,   0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(200,  95,display_tmp->time_frame,display_tmp->screen);
   apply_surface(295, 310,display_tmp->thermometer_pic,display_tmp->screen);
   apply_surface(680, 365,display_tmp->next_button,display_tmp->screen);

   display_reflash_main(display_tmp,state);
   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;

   //Timer runing for two seconds
   display_tmp->reflash_timer = SDL_AddTimer ((2000/10)*10,
                                               display_set_sdl_userevent,NULL); 

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);

      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){
         uint8_t button_pressed = 0;
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 NEXT_BUTTON);
         //After pressing the Next_Button the screen jumps to the choosescreen
         if(button_pressed == 1){
            *state= CHOOSEWINDOW;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 ROOM_BUTTON);
         //After pressing the Room_Button the screen jumps to the showscreen
         if(button_pressed == 1){
            *state= SHOWWINDOWLIVING;
            post_state = 1;
         }
       }
       //After the timer is run out the screen reloading
       if(display_tmp->event.type == SDL_USEREVENT){

              display_reflash_main(display_tmp, state);  
       }
   } 
   //Remove the eventtimer  
   SDL_RemoveTimer (display_tmp->reflash_timer); 

}

//Choosescreen of the homeapplication
void display_choose_window(display_menue *display_tmp, uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0,  0,display_tmp->main_frame,display_tmp->screen);
   apply_surface( 90, 60,display_tmp->work_frame,display_tmp->screen);
   apply_surface(330, 60,display_tmp->living_frame,display_tmp->screen);
   apply_surface(560, 60,display_tmp->sleep_frame,display_tmp->screen); 
   apply_surface(210,250,display_tmp->kitchen_frame,display_tmp->screen);
   apply_surface(450,250,display_tmp->bath_frame,display_tmp->screen);
   apply_surface(710,400,display_tmp->home_button,display_tmp->screen);  
   apply_surface(127,125,display_tmp->work_text,display_tmp->screen); 
   apply_surface(365,125,display_tmp->living_text,display_tmp->screen);
   apply_surface(591,125,display_tmp->sleep_text,display_tmp->screen); 
   apply_surface(250,315,display_tmp->kitchen_text,display_tmp->screen);
   apply_surface(505,315,display_tmp->bath_text,display_tmp->screen);
   
   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;

   //Timer runing for thirty seconds
   display_tmp->home_timer = SDL_AddTimer ((30000/10)*10,
                                               display_set_sdl_userevent,NULL); 

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);
      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){
        
         uint8_t button_pressed = 1;
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 WORK_BUTTON);   
         //After pressing the Work_Button the screen jumps to the showscreen of work     
         if(button_pressed == 1){
            *state= SHOWWINDOWWORK;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 BATH_BUTTON);
         //After pressing the Bath_Button the screen jumps to the showscreen of bath
         if(button_pressed == 1){
            *state= SHOWWINDOWBATH;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 LIVING_BUTTON);
         //After pressing the Living_Button the screen jumps to the showscreen of living
         if(button_pressed == 1){
            *state= SHOWWINDOWLIVING;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 KITCHEN_BUTTON);
         //After pressing the Kitchen_Button the screen jumps to the showscreen of kitchen
         if(button_pressed == 1){
            *state= SHOWWINDOWKITCHEN;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 SLEEP_BUTTON);
         //After pressing the Sleep_Button the screen jumps to the showscreen of sleep
         if(button_pressed == 1){
            *state= SHOWWINDOWSLEEP;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HOME_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= MAINWINDOW;
            post_state = 1;
         }
       }
       //After the timer is run out the screen jumps to the mainwindow
       if(display_tmp->event.type == SDL_USEREVENT){
           
           *state= MAINWINDOW;
           post_state = 1;      
       }   
   }
   //Remove the eventtimer
   SDL_RemoveTimer (display_tmp->home_timer); 
 
}

//Showscreen of the homeapplication
void display_show_window(display_menue *display_tmp, uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0 , 0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(115, 60,display_tmp->roomtitle_frame,display_tmp->screen); 
   apply_surface(220,370,display_tmp->small_thermometer_pic,display_tmp->screen);
   apply_surface(515,370,display_tmp->window_pic,display_tmp->screen); 
   apply_surface(660,400,display_tmp->back_button,display_tmp->screen);
   apply_surface(710,400,display_tmp->home_button,display_tmp->screen);   

   switch(*state){
     case SHOWWINDOWWORK:
           apply_surface(295, 70,display_tmp->showwork_text,display_tmp->screen);
           break;
     case SHOWWINDOWSLEEP:
           apply_surface(305, 70,display_tmp->showsleep_text,display_tmp->screen);
           break;
     case SHOWWINDOWLIVING:
           apply_surface(305, 70,display_tmp->showliving_text,display_tmp->screen);
           break;
     case SHOWWINDOWKITCHEN:
           apply_surface(340, 70,display_tmp->showkitchen_text,display_tmp->screen);
           break;
     case SHOWWINDOWBATH:
           apply_surface(305, 70,display_tmp->showbath_text,display_tmp->screen);
           break;
   }

   int i= 0;
   display_reflash_show(display_tmp, state);

   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;
   
   //Timer runing for two seconds
   display_tmp->home_timer = SDL_AddTimer ((2000/10)*10,
                                            display_set_sdl_userevent,NULL);

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);
      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){
        
         uint8_t button_pressed = 1;
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 BACK_BUTTON);
         //After pressing the Back_Button the screen jumps to the choosescreen     
         if(button_pressed == 1){
            *state= CHOOSEWINDOW;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HOME_BUTTON);
         //After pressing the Home_Button the screen jumps to mainwindow
         if(button_pressed == 1){
            *state= MAINWINDOW;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HIDDEN_BUTTON);
         //After pressing the HIDDEN_Button the pragramm exits
         if(button_pressed == 1){
            *state= PROGRAM_EXIT;
            post_state = 1;
         }
       }
       if(display_tmp->event.type == SDL_USEREVENT){
          i++;
          if(i < 15){
              
              display_reflash_show(display_tmp, state);
          }else{ 
             //After the timer is run out the screen jumps to the mainwindow
             *state= MAINWINDOW;
              post_state = 1;
          }    
       }
   }
   //Remove the eventtimer
   SDL_RemoveTimer (display_tmp->home_timer);  

}

/*----------------------------------WORK---------------------------------------*/

//Mainscreen of the workapplication
void display_main_window_work(display_menue *display_tmp ,uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0,   0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(200,  95,display_tmp->little_watch_frame,display_tmp->screen);
   apply_surface(680, 365,display_tmp->next_button,display_tmp->screen);

   display_reflash_main_work(display_tmp,state);
   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;

   //Timer runing for two seconds
   display_tmp->reflash_timer = SDL_AddTimer ((2000/10)*10,
                                               display_set_sdl_userevent,NULL); 

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);

      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){
         uint8_t button_pressed = 0;
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 NEXT_BUTTON);
         //After pressing the Next_Button the screen jumps to the choosescreen
         if(button_pressed == 1){
            *state= ROOMLIST;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 SEMI_BUTTON);
         //After pressing the SEMI_Button the screen jumps to the Seminar room two (S 101)
         if(button_pressed == 1){
            *state= SECOND_SEMINAR_ROOM;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 ROOM_BUTTON);
         //After pressing the Room_Button the screen jumps to the showscreen
         if(button_pressed == 1){
            *state= SHOWWINDOWLIVING;
            post_state = 1;
         }
       }
       //After the timer is run out the screen reloading
       if(display_tmp->event.type == SDL_USEREVENT){

          display_reflash_main_work(display_tmp, state);  
       }
   } 
   //Remove the eventtimer  
   SDL_RemoveTimer (display_tmp->reflash_timer); 

}

//Roomlist of the workapplication
void display_roomlist_window(display_menue *display_tmp, uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0,  0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(710,400,display_tmp->home_button,display_tmp->screen); 
   apply_surface(100,110,display_tmp->semi_room_frame,display_tmp->screen); 
   apply_surface(410,110,display_tmp->bureau_frame,display_tmp->screen); 
   apply_surface(100, 50,display_tmp->list_title_frame,display_tmp->screen);  
   apply_surface(120,130,display_tmp->info_semi1_button,display_tmp->screen); 
   apply_surface(120,190,display_tmp->info_semi2_button,display_tmp->screen); 
   apply_surface(120,250,display_tmp->info_semi3_button,display_tmp->screen); 
   apply_surface(120,310,display_tmp->info_semi4_button,display_tmp->screen); 
   apply_surface(470,170,display_tmp->info_bureau1_button,display_tmp->screen); 
   apply_surface(470,270,display_tmp->info_bureau2_button,display_tmp->screen); 
   apply_surface(110, 53,display_tmp->title_text,display_tmp->screen); 
   apply_surface(180,140,display_tmp->semi1_text,display_tmp->screen); 
   apply_surface(180,200,display_tmp->semi2_text,display_tmp->screen); 
   apply_surface(180,260,display_tmp->semi3_text,display_tmp->screen); 
   apply_surface(180,320,display_tmp->semi4_text,display_tmp->screen); 
   apply_surface(530,180,display_tmp->bureau1_text,display_tmp->screen); 
   apply_surface(530,280,display_tmp->bureau2_text,display_tmp->screen); 
   apply_surface(180,170,display_tmp->roomname_semi1_text,display_tmp->screen); 
   apply_surface(180,230,display_tmp->roomname_semi2_text,display_tmp->screen); 
   apply_surface(180,290,display_tmp->roomname_semi3_text,display_tmp->screen); 
   apply_surface(180,350,display_tmp->roomname_semi4_text,display_tmp->screen); 
   apply_surface(530,210,display_tmp->roomname_bureau1_text,display_tmp->screen); 
   apply_surface(530,310,display_tmp->roomname_bureau2_text,display_tmp->screen); 
   
   display_reflash_roomlist(display_tmp, state);
   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;

   int i= 0;

   //Timer runing for thirty seconds
   display_tmp->home_timer = SDL_AddTimer ((2000/10)*10,
                                               display_set_sdl_userevent,NULL); 

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);
      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){
        
         uint8_t button_pressed = 1;

         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HOME_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= MAINWINDOW_WORK;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 SEMI1_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= FIRST_SEMINAR_ROOM;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 SEMI2_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= SECOND_SEMINAR_ROOM;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 SEMI3_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= THIRD_SEMINAR_ROOM;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 SEMI4_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= FOURT_SEMINAR_ROOM;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 BUREAU1_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= FIRST_BUREAU;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 BUREAU2_BUTTON);
         //After pressing the Home_Button the screen jumps to the mainwindow
         if(button_pressed == 1){
            *state= SECOND_BUREAU;
            post_state = 1;
         }
       }
       if(display_tmp->event.type == SDL_USEREVENT){
          i++;
          if(i < 15){
              
              display_reflash_roomlist(display_tmp, state);
          }else{ 
             //After the timer is run out the screen jumps to the mainwindow
             *state= MAINWINDOW_WORK;
              post_state = 1;
          }    
       }
    }
   //Remove the eventtimer
   SDL_RemoveTimer (display_tmp->home_timer); 
 
}

//Bureauscreen
void display_bureau_window(display_menue *display_tmp, uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0 , 0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(660,400,display_tmp->back_button,display_tmp->screen);
   apply_surface(710,400,display_tmp->home_button,display_tmp->screen);  
   apply_surface(100, 50,display_tmp->timetable_frame,display_tmp->screen);
   apply_surface(100,310,display_tmp->timetable_info_frame,display_tmp->screen);   

   switch(*state){
     case FIRST_BUREAU:
           apply_surface(125, 70,display_tmp->bureau1_time_text,display_tmp->screen);
           apply_surface(125,100,display_tmp->bureau1_time1_text,display_tmp->screen);
           apply_surface(125,130,display_tmp->bureau1_time2_text,display_tmp->screen);
           apply_surface(125,160,display_tmp->bureau1_time3_text,display_tmp->screen);
           apply_surface(125,190,display_tmp->bureau1_time4_text,display_tmp->screen);
           apply_surface(125,220,display_tmp->bureau1_time5_text,display_tmp->screen);
           apply_surface(270,320,display_tmp->bureau1_info1_text,display_tmp->screen);
           apply_surface(260,350,display_tmp->bureau1_info2_text,display_tmp->screen);
           break;
     case SECOND_BUREAU:
           apply_surface(125, 70,display_tmp->bureau2_time_text,display_tmp->screen);
           apply_surface(125,100,display_tmp->bureau2_time1_text,display_tmp->screen);
           apply_surface(125,130,display_tmp->bureau2_time2_text,display_tmp->screen);
           apply_surface(125,160,display_tmp->bureau2_time3_text,display_tmp->screen);
           apply_surface(125,190,display_tmp->bureau2_time4_text,display_tmp->screen);
           apply_surface(125,220,display_tmp->bureau2_time5_text,display_tmp->screen);
           apply_surface(200,320,display_tmp->bureau2_info1_text,display_tmp->screen);
           apply_surface(175,350,display_tmp->bureau2_info2_text,display_tmp->screen);
           break;
   }

   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;
   
   //Timer runing for two seconds
   display_tmp->home_timer = SDL_AddTimer ((30000/10)*10,
                                            display_set_sdl_userevent,NULL);

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);
      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){
        
         uint8_t button_pressed = 1;
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 BACK_BUTTON);
         //After pressing the Back_Button the screen jumps to the roomlistscreen     
         if(button_pressed == 1){
            *state= ROOMLIST;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HOME_BUTTON);
         //After pressing the Home_Button the screen jumps to mainwindow
         if(button_pressed == 1){
            *state= MAINWINDOW_WORK;
            post_state = 1;
         }
       }
       if(display_tmp->event.type == SDL_USEREVENT){
          *state= MAINWINDOW_WORK;
          post_state = 1;
             
       }
   }
   //Remove the eventtimer
   SDL_RemoveTimer (display_tmp->home_timer);  

}

//Seminarroomscreen
void display_seminar_window(display_menue *display_tmp, uint8_t *state){

   //Positioning of the pictures on the screen
   apply_surface(  0 , 0,display_tmp->main_frame,display_tmp->screen);
   apply_surface(660,400,display_tmp->back_button,display_tmp->screen);
   apply_surface(710,400,display_tmp->home_button,display_tmp->screen);  
   apply_surface(100, 50,display_tmp->semi_room_free_frame,display_tmp->screen);
   apply_surface(100,100,display_tmp->semi_info_frame,display_tmp->screen);
   apply_surface(100,190,display_tmp->next_room_info_frame,display_tmp->screen);   
   apply_surface(240,200,display_tmp->semi_text,display_tmp->screen);  

   switch(*state){
     case FIRST_SEMINAR_ROOM :
           apply_surface(220, 60,display_tmp->semi1_title_text,display_tmp->screen);
           apply_surface(120, 120,display_tmp->semi1_info_text,display_tmp->screen);
           break;
     case SECOND_SEMINAR_ROOM :
           apply_surface(220, 60,display_tmp->semi2_title_text,display_tmp->screen);
           apply_surface(120, 120,display_tmp->semi2_info_text,display_tmp->screen);
           break;
     case THIRD_SEMINAR_ROOM :
           apply_surface(220, 60,display_tmp->semi3_title_text,display_tmp->screen);
           apply_surface(120, 120,display_tmp->semi3_info_text,display_tmp->screen);
           break;
     case FOURT_SEMINAR_ROOM :
           apply_surface(220, 60,display_tmp->semi4_title_text,display_tmp->screen);
           apply_surface(120, 120,display_tmp->semi4_info_text,display_tmp->screen);
           break;
   }

   int i= 0;
   display_reflash_seminarroom(display_tmp, state);

   //Show the pictures on the screen
   SDL_Flip(display_tmp->screen);

   uint8_t post_state =0;
   uint8_t pre_state = 0;
   
   //Timer runing for two seconds
   display_tmp->home_timer = SDL_AddTimer ((2000/10)*10,
                                            display_set_sdl_userevent,NULL);

   while( pre_state == post_state ){
      //Waiting till something is happened on the screen like a mouse was moved
      SDL_WaitEvent ( &display_tmp->event);
      //Eventhandling
      if(display_tmp->event.type == SDL_MOUSEBUTTONDOWN){        
         uint8_t button_pressed = 1;
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 BACK_BUTTON);
         //After pressing the Back_Button the screen jumps to the roomlistscreen     
         if(button_pressed == 1){
            *state= ROOMLIST;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HOME_BUTTON);
         //After pressing the Home_Button the screen jumps to mainwindow
         if(button_pressed == 1){
            *state= MAINWINDOW_WORK;
            post_state = 1;
         }
         button_pressed = display_button_pressed(display_tmp->event.button.x,
                                                 display_tmp->event.button.y,
                                                 HIDDEN_BUTTON);         
         //After pressing the HIDDEN_Button the pragramm exits
         if(button_pressed == 1){
            
            *state= PROGRAM_EXIT;
            post_state = 1;
         }
       }
       if(display_tmp->event.type == SDL_USEREVENT){
          i++;
          if(i < 15){
              
              display_reflash_seminarroom(display_tmp, state);
          }else{ 
             //After the timer is run out the screen jumps to the mainwindow
             *state= MAINWINDOW_WORK;
              post_state = 1;
          }    
       }
   }
   //Remove the eventttest100imer
   SDL_RemoveTimer (display_tmp->home_timer);  

}


//Funktion to easier positioning of pictures
void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination){
    
    SDL_Rect rect_temp;

    rect_temp.x = x;
    rect_temp.y = y;
    SDL_BlitSurface(source,NULL,destination,&rect_temp);     

}

//Positioning of the Buttons on the screen
uint8_t display_button_pressed(uint16_t x, uint16_t y, uint8_t button_tmp){
    switch(button_tmp){
       case NEXT_BUTTON:
          if ((x >= 680 && x <= 780) && (y >= 365 && y <= 415))
             return 1;
          return 0;
          break;
       case SLEEP_BUTTON:
          if ((x >= 560 && x <= 710) && (y >= 60 && y <= 217))
             return 1;
          return 0;
          break;
       case BATH_BUTTON:
          if ((x >= 450 && x <= 600) && (y >= 250 && y <= 407))
             return 1;
          return 0;
          break;
       case WORK_BUTTON:
          if ((x >= 90 && x <= 240) && (y >= 60 && y <= 217))
             return 1;
          return 0;
          break;
       case KITCHEN_BUTTON:
          if ((x >= 210 && x <= 360) && (y >= 250 && y <= 407))
             return 1;
          return 0;
          break;
       case LIVING_BUTTON:
          if ((x >= 330 && x <= 480) && (y >= 60 && y <= 217))
             return 1;
          return 0;
          break;
       case HOME_BUTTON:
          if ((x >= 710 && x <= 760) && (y >= 400 && y <= 450))
             return 1;
          return 0;
          break;
       case BACK_BUTTON:
          if ((x >= 660 && x <= 710) && (y >= 400 && y <= 450))
             return 1;
          return 0;
          break;
       case ROOM_BUTTON:
          if ((x >= 295 && x <= 345) && (y >= 310 && y <= 410))
             return 1;
          return 0;
          break;

       /* Buttons from workmenue */
       case SEMI_BUTTON:
          if ((x >= 150 && x <= 655) && (y >=  90 && y <= 260))
             return 1;
          return 0;
          break;
       case SEMI1_BUTTON:
          if ((x >= 120 && x <= 170) && (y >= 130 && y <= 180))
             return 1;
          return 0;
          break;
       case SEMI2_BUTTON:
          if ((x >= 120 && x <= 170) && (y >= 190 && y <= 240))
             return 1;
          return 0;
          break;
       case SEMI3_BUTTON:
          if ((x >= 120 && x <= 170) && (y >= 250 && y <= 300))
             return 1;
          return 0;
          break;
       case SEMI4_BUTTON:
          if ((x >= 120 && x <= 170) && (y >= 310 && y <= 360))
             return 1;
          return 0;
          break;
       case BUREAU1_BUTTON:
          if ((x >= 470 && x <= 520) && (y >= 170 && y <= 320))
             return 1;
          return 0;
          break;
       case BUREAU2_BUTTON:
          if ((x >= 470 && x <= 520) && (y >= 270 && y <= 320))
             return 1;
          return 0;
          break;
       case HIDDEN_BUTTON:
          if ((x >= 0 && x <= 50) && (y >= 0 && y <= 50))
             return 1;
          return 0;
          break;
    } 
    return 0; 

}

void display_clean(display_menue *display_tmp ,uint8_t *state){

     SDL_FreeSurface(display_tmp->next_button);
     SDL_FreeSurface(display_tmp->home_button);
     SDL_FreeSurface(display_tmp->back_button);
     SDL_FreeSurface(display_tmp->main_frame);
     SDL_FreeSurface(display_tmp->time_frame);
     SDL_FreeSurface(display_tmp->thermometer_pic);
     SDL_FreeSurface(display_tmp->small_thermometer_pic);
     SDL_FreeSurface(display_tmp->window_pic);
     SDL_FreeSurface(display_tmp->work_frame);
     SDL_FreeSurface(display_tmp->living_frame);
     SDL_FreeSurface(display_tmp->bath_frame);
     SDL_FreeSurface(display_tmp->kitchen_frame);
     SDL_FreeSurface(display_tmp->sleep_frame);
     SDL_FreeSurface(display_tmp->roomtempr_frame);
     SDL_FreeSurface(display_tmp->roomwindow_frame);
     SDL_FreeSurface(display_tmp->roomtitle_frame);
     SDL_FreeSurface(display_tmp->little_watch_frame);
     SDL_FreeSurface(display_tmp->semi_room_frame);
     SDL_FreeSurface(display_tmp->bureau_frame);
     SDL_FreeSurface(display_tmp->list_title_frame);
     SDL_FreeSurface(display_tmp->timetable_frame);
     SDL_FreeSurface(display_tmp->timetable_info_frame);
     SDL_FreeSurface(display_tmp->semi_room_free_frame);
     SDL_FreeSurface(display_tmp->semi_allocation1_frame);
     SDL_FreeSurface(display_tmp->semi_allocation2_frame);
     SDL_FreeSurface(display_tmp->semi_info_frame);
     SDL_FreeSurface(display_tmp->next_room_info_frame);
     SDL_FreeSurface(display_tmp->red_frame);
     SDL_FreeSurface(display_tmp->green_frame);
     SDL_FreeSurface(display_tmp->red_pic);
     SDL_FreeSurface(display_tmp->green_pic);
     SDL_FreeSurface(display_tmp->red1_pic);
     SDL_FreeSurface(display_tmp->green1_pic);
     SDL_FreeSurface(display_tmp->red2_pic);
     SDL_FreeSurface(display_tmp->green2_pic);
     SDL_FreeSurface(display_tmp->red3_pic);
     SDL_FreeSurface(display_tmp->green3_pic);
     SDL_FreeSurface(display_tmp->info_semi1_button);
     SDL_FreeSurface(display_tmp->info_semi2_button);
     SDL_FreeSurface(display_tmp->info_semi3_button);
     SDL_FreeSurface(display_tmp->info_semi4_button);
     SDL_FreeSurface(display_tmp->info_bureau1_button);
     SDL_FreeSurface(display_tmp->info_bureau2_button);
     SDL_FreeSurface(display_tmp->screen);
     SDL_FreeSurface(display_tmp->work_text);
     SDL_FreeSurface(display_tmp->living_text);
     SDL_FreeSurface(display_tmp->bath_text);
     SDL_FreeSurface(display_tmp->kitchen_text);
     SDL_FreeSurface(display_tmp->sleep_text);
     SDL_FreeSurface(display_tmp->showwork_text);
     SDL_FreeSurface(display_tmp->showliving_text);
     SDL_FreeSurface(display_tmp->showbath_text);
     SDL_FreeSurface(display_tmp->showkitchen_text);
     SDL_FreeSurface(display_tmp->showsleep_text);
     SDL_FreeSurface(display_tmp->watch_text);   
     SDL_FreeSurface(display_tmp->title_text);
     SDL_FreeSurface(display_tmp->semi1_text);
     SDL_FreeSurface(display_tmp->semi2_text);
     SDL_FreeSurface(display_tmp->semi3_text);
     SDL_FreeSurface(display_tmp->semi4_text); 
     SDL_FreeSurface(display_tmp->roomname_semi1_text); 
     SDL_FreeSurface(display_tmp->roomname_semi2_text); 
     SDL_FreeSurface(display_tmp->roomname_semi3_text); 
     SDL_FreeSurface(display_tmp->roomname_semi4_text); 
     SDL_FreeSurface(display_tmp->roomname_bureau1_text); 
     SDL_FreeSurface(display_tmp->roomname_bureau2_text); 
     SDL_FreeSurface(display_tmp->bureau1_text); 
     SDL_FreeSurface(display_tmp->bureau2_text);   
     SDL_FreeSurface(display_tmp->bureau1_time_text);  
     SDL_FreeSurface(display_tmp->bureau1_time1_text); 
     SDL_FreeSurface(display_tmp->bureau1_time2_text); 
     SDL_FreeSurface(display_tmp->bureau1_time3_text); 
     SDL_FreeSurface(display_tmp->bureau1_time4_text); 
     SDL_FreeSurface(display_tmp->bureau1_time5_text);
     SDL_FreeSurface(display_tmp->bureau1_info1_text); 
     SDL_FreeSurface(display_tmp->bureau1_info2_text);   
     SDL_FreeSurface(display_tmp->bureau2_time_text); 
     SDL_FreeSurface(display_tmp->bureau2_time1_text); 
     SDL_FreeSurface(display_tmp->bureau2_time2_text); 
     SDL_FreeSurface(display_tmp->bureau2_time3_text); 
     SDL_FreeSurface(display_tmp->bureau2_time4_text); 
     SDL_FreeSurface(display_tmp->bureau2_time5_text);
     SDL_FreeSurface(display_tmp->bureau2_info1_text); 
     SDL_FreeSurface(display_tmp->bureau2_info2_text);
     SDL_FreeSurface(display_tmp->semi_text);
     SDL_FreeSurface(display_tmp->semi1_title_text);
     SDL_FreeSurface(display_tmp->semi1_info_text);  
     SDL_FreeSurface(display_tmp->semi2_title_text);
     SDL_FreeSurface(display_tmp->semi2_info_text);
     SDL_FreeSurface(display_tmp->semi3_title_text);
     SDL_FreeSurface(display_tmp->semi3_info_text);
     SDL_FreeSurface(display_tmp->semi4_title_text);
     SDL_FreeSurface(display_tmp->semi4_info_text);
     SDL_FreeSurface(display_tmp->semi_full_text);
     SDL_FreeSurface(display_tmp->semi_free_text);
     SDL_FreeSurface(display_tmp->red_text);
     SDL_FreeSurface(display_tmp->green_text);
     SDL_FreeSurface(display_tmp->roomstat_text);

     TTF_CloseFont(display_tmp->font_liberation_minimal);
     TTF_CloseFont(display_tmp->font_liberation_mini);
     TTF_CloseFont(display_tmp->font_liberation_small);
     TTF_CloseFont(display_tmp->font_liberation_middle);
     TTF_CloseFont(display_tmp->font_liberation_normal);
     TTF_CloseFont(display_tmp->font_liberation_tall);
     TTF_CloseFont(display_tmp->font_liberation_taller);
     TTF_CloseFont(display_tmp->font_liberation_big);

     TTF_Quit();
     //Quit SDL
     SDL_Quit();
}

